package interview.mininarray;

public class MinInArray {
	// Assuming the array is sorted ascendingly and shifted
	public int min(int[] array) {
		if(array[0] < array[array.length - 1]) {
			return array[0];
		}

		int left = 0;
		int right = array.length - 1;
		int mid;
		while(true) {
			mid = left + (right - left) / 2;
			if(array[mid] < array[mid - 1]) {
				return array[mid];
			} else if (array[mid] > array[0]) {
				left = mid + 1;
			} else {
				right = mid - 1;
			}
		}
	}
}
